package com.easyattendance.model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "TBL_MATERIAL")
public class Material {

	@Id
	@Column(name = "material_id",length=10)
	private String material_id;
	
	@Column(name = "material_name",length=50)
	private String material_name;
	
	@Column(name = "material_type", length = 10,nullable=false)
	private String material_type;

	@Column(name = "uploaded_by", length = 32,nullable=false)
	private String uploaded_by;

	@Column(name = "physical_path", length = 255,nullable=false)
	private String physical_path;
	
	/* one to one mapping of material */
	/*@OneToOne(mappedBy="material", fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private MaterialClass materialClass;
	
	@OneToOne(mappedBy="material", fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private MaterialSection materialSection; */
	
	@OneToMany(mappedBy="material", fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<MaterialClass> materialClass;
	
	@OneToMany(mappedBy="material", fetch=FetchType.LAZY)
	@Cascade(value = {org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
	private Set<MaterialSection> materialSection;
	
	public Material()
	{
		
	}

	public Material(String material_id,String material_name,String material_type, String uploaded_by, String physical_path) {
		super();
		this.material_id = material_id;
		this.material_name = material_name;
		this.material_type = material_type;
		this.uploaded_by = uploaded_by;
		this.physical_path = physical_path;
	}

	public String getMaterial_id() {
		return material_id;
	}

	public void setMaterial_id(String material_id) {
		this.material_id = material_id;
	}

	public String getMaterial_type() {
		return material_type;
	}

	public void setMaterial_type(String material_type) {
		this.material_type = material_type;
	}

	public String getUploaded_by() {
		return uploaded_by;
	}

	public void setUploaded_by(String uploaded_by) {
		this.uploaded_by = uploaded_by;
	}

	public String getPhysical_path() {
		return physical_path;
	}

	public void setPhysical_path(String physical_path) {
		this.physical_path = physical_path;
	}

	public Set<MaterialClass> getMaterialClass() {
		return materialClass;
	}

	public void setMaterialClass(Set<MaterialClass> materialClass) {
		this.materialClass = materialClass;
	}

	public Set<MaterialSection> getMaterialSection() {
		return materialSection;
	}

	public void setMaterialSection(Set<MaterialSection> materialSection) {
		this.materialSection = materialSection;
	}
	
	public String getMaterial_name() {
		return material_name;
	}

	public void setMaterial_name(String material_name) {
		this.material_name = material_name;
	}
	
	

	public Material(String material_name, String physical_path) {
		super();
		this.material_name = material_name;
		this.physical_path = physical_path;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((material_id == null) ? 0 : material_id.hashCode());
		result = prime * result
				+ ((material_type == null) ? 0 : material_type.hashCode());
		result = prime * result
				+ ((physical_path == null) ? 0 : physical_path.hashCode());
		result = prime * result
				+ ((uploaded_by == null) ? 0 : uploaded_by.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Material other = (Material) obj;
		if (material_id == null) {
			if (other.material_id != null)
				return false;
		} else if (!material_id.equals(other.material_id))
			return false;
		if (material_type == null) {
			if (other.material_type != null)
				return false;
		} else if (!material_type.equals(other.material_type))
			return false;
		if (physical_path == null) {
			if (other.physical_path != null)
				return false;
		} else if (!physical_path.equals(other.physical_path))
			return false;
		if (uploaded_by == null) {
			if (other.uploaded_by != null)
				return false;
		} else if (!uploaded_by.equals(other.uploaded_by))
			return false;
		return true;
	}

	
}
